package com.leo.platform.shop.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.leo.platform.common.dao.BaseDao;
import com.leo.platform.shop.entity.probrand.ProBrand;

@org.apache.ibatis.annotations.Mapper
public interface ProBrandDao extends BaseDao<ProBrand, Long> {
    /**
     * 新增商品分类和品牌中间表数据
     */
    @Insert("INSERT INTO bsp_procategoryref (categoryId, entityCode, entityType) VALUES (#{categoryId},#{entityCode},'brand')")
        void insertCategoryBrand(@Param("categoryId") Long categoryId, @Param("entityCode") String entityCode);

    /**
     * 根据entitycode删除中间表相关数据
     */
    @Delete("DELETE FROM bsp_procategoryref WHERE entityCode = #{entityCode} AND entityType = 'brand'")
    void deleteByBrandCodeInCategoryRef(@Param("entityCode") String entityCode);

    /**
     * 根据category id查询brand,左连接
     */
    @Select("SELECT b.* FROM bsp_probrand b LEFT JOIN bsp_procategoryref cb ON b.code=cb.entityCode WHERE cb.categoryId=#{categoryId} AND cb.entityType='brand'")
        List<ProBrand> queryBrandByCategoryId(@Param("categoryId") Long categoryId);
}